/******************************************************************************
COPYRIGHT (C) 2013 by IT-Designers GmbH

File:		Line2D.h
Created:	25.02.2013
Modified:	04.04.2013
Author:		Max Pejs
******************************************************************************/

#ifndef LINE2D_H
#define LINE2D_H

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>

#define PI		3.1415926535897932384626433832795

using namespace cv;
using namespace std;

class Line2D
{
private:
	
	Point2d originNormalVect;

	void CalcHesseParams();
	void UpdateParams();
	
public:
	bool operator< (const Line2D& r) const;
	
	Point2d Start, End;
	double Rho;		// angle of normal vector
	double Theta;	// distance to origin

	Line2D();

	/// /fn		CvLabel Line2D(Vec4i & CVLine)
	/// /brief	Ctor. 
	/// /param	CVLine represents a 4-element vector (x1,y1,x2,y2), 
	///			where (x1, y1) and (x2, y2) are the ending points of each detected line segment.
	Line2D(Vec4i & CVLine);

	Line2D(double rho, double theta, double upperYlim, double lowerYlim);

	/// /fn		CvLabel Line2D(Vec4i & CVLine)
	/// /brief	Ctor. 
	/// /param	Start represents the first ending point of the line.
	/// /param	End represents the second ending point of the line.
	Line2D(Point2d & Start, Point2d & End);
	~Line2D();
	
	bool Intersection(Point2d o, Point2d p, Point2d & r);
	
	bool Intersection(Line2D & line, Point2d & r);
	
	double Distance(Point2d & other);
	
	void plotLineToImg(Mat & img, Scalar color = Scalar(0,255,0));
	
	void PlotParameters(Mat & img, Scalar color = CV_RGB(0, 255, 0), Point & offset = Point(0,0));

	void Transform(Mat & H);
	
	void Move(Point2d & offset);
	
	/****** Getters *********/

	double Slope() const;

	Point2d OriginNormalVect(void) const;

	static void TransformPoint(Mat & H, Point2d & point2D);
};

#endif	// LINE2D_H